﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using BLL;
using Model; 
namespace webApi.Controllers
{
    public class StudentsController : ApiController
    {
        //GradeServes grade = new GradeServes();
        StudentServes studen = new StudentServes();


        public IHttpActionResult GetStuinfo()
        {
            var list = studen.GetList(o => true).Select(n => new { n.id, n.StrName, n.sex, n.Grade.GradeName, married = n.Married == true ? "已婚" : "未婚" });
            return Ok(new { rows = list, total = list.Count() });
        }


        [HttpPost]
        public IHttpActionResult GetAdd(Student stu) 
        {
            if (studen.Add(stu))
            {
                return Ok('1');
            }
            return Ok('0');
        }
         
        [HttpGet]
        public IHttpActionResult GetDel(int id) 
        {
            if (studen.Delete(o=>o.id==id))
            {
                return Ok('1');
            }
            return Ok('0');
        }


    }
}
